/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author Arkan
 */
public class DialogoSolicitarCertificado extends JDialog implements ActionListener
{
    private final static String ACEPTAR = "Aceptar";
    
    private final static String CANCELAR = "Cancelar";
    
    private InterfazFotosP2P principal;
    
    private JLabel labContrsenia;
    
    private JPasswordField passContrasenia;
    
    private JButton butAceptar;
    
    private JButton butCancelar;
    
    public DialogoSolicitarCertificado( InterfazFotosP2P ventana )
    {
        principal = ventana;
        
        setTitle( "Solicitar Certificado" );
        setLayout( new GridBagLayout( ) );
        setSize( 330, 120 );
        setResizable( false );
        setLocationRelativeTo( principal );
        setModal( true );
        
        labContrsenia = new JLabel( "Asigne una contraseña para proteger su llave privada" );
        GridBagConstraints gbc = new GridBagConstraints( );
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 2;
        gbc.anchor = GridBagConstraints.WEST;
        add( labContrsenia, gbc );
        
        passContrasenia = new JPasswordField( );
        gbc = new GridBagConstraints( );
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 2;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        add( passContrasenia, gbc );
        
        butAceptar = new JButton( ACEPTAR );
        butAceptar.setActionCommand( ACEPTAR );
        butAceptar.addActionListener( this );
        gbc = new GridBagConstraints( );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets( 0, 0, 0, 2 );
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        add( butAceptar, gbc );
        
        butCancelar = new JButton( CANCELAR );
        butCancelar.setActionCommand( CANCELAR );
        butCancelar.addActionListener( this );
        gbc = new GridBagConstraints( );
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets( 0, 2, 0, 0 );
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        add( butCancelar, gbc );
    }
    
    public void actionPerformed( ActionEvent e )
    {
        String comando = e.getActionCommand( );
        
        if( comando.equals( ACEPTAR ) )
        {
            
           principal.generarCertificado(passContrasenia.getText());
           dispose();
        }
        else if( comando.equals( CANCELAR ) )
        {
            dispose( );
        }
    }
}
